{"componentChunkName":"component---src-templates-post-jsx","path":"/[CS]Array&ArrayList&LinkedList/","result":{"data":{"site":{"siteMetadata":{"title":"SUbbb"}},"markdownRemark":{"id":"57149a6b-c730-5ce4-a3c5-9cea44979c8c","excerpt":"🧷 세 자료 구조  : index로 빠르게 값을 찾는 것이 가능  : 데이터의 삽입 및 삭제가 빠름  : 데이터를 찾는 것은 빠르지만, 삽입 및 삭제가 느림 🪚 더 자세한 비교 Array 선언할 때 크기와 데이터 타입을 지정해야 한다. 메모리 공간에 사용할 사이즈를 미리 할당해두고 사용하는 자료구조다. 따라서 계속 데이터가 늘어날 경우, 최대 사이즈를 알…","html":"<h2>🧷 세 자료 구조</h2>\n<ul>\n<li><code class=\"language-text\">Array</code> : index로 빠르게 값을 찾는 것이 가능</li>\n<li><code class=\"language-text\">LinkedList</code> : 데이터의 삽입 및 삭제가 빠름</li>\n<li><code class=\"language-text\">ArrayList</code> : 데이터를 찾는 것은 빠르지만, 삽입 및 삭제가 느림</li>\n</ul>\n<h3>🪚 더 자세한 비교</h3>\n<p><strong>Array</strong></p>\n<ul>\n<li>선언할 때 <strong>크기와 데이터 타입을 지정</strong>해야 한다.</li>\n<li>\n<p>메모리 공간에 사용할 사이즈를 미리 할당해두고 사용하는 자료구조다.</p>\n<ul>\n<li>따라서 계속 데이터가 늘어날 경우, 최대 사이즈를 알 수 없을 때 사용하기는 부적합하다.</li>\n<li>또한 중간에 데이터를 삽입 및 삭제하는 것도 매우 비효율적이다. (접근하여 삭제한 뒤, 나머지 뒷 데이터들을 <code class=\"language-text\">shift</code> 해주는 비용으로 인해 최악의 경우 <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><mi>N</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(N)</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1em;vertical-align:-0.25em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.02778em;\">O</span><span class=\"mopen\">(</span><span class=\"mord mathnormal\" style=\"margin-right:0.10903em;\">N</span><span class=\"mclose\">)</span></span></span></span>)</li>\n<li>대신, <code class=\"language-text\">index</code> 를 통해 검색을 <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><mn>1</mn><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(1)</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1em;vertical-align:-0.25em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.02778em;\">O</span><span class=\"mopen\">(</span><span class=\"mord\">1</span><span class=\"mclose\">)</span></span></span></span>에 수행할 수 있다는 장점이 있다.</li>\n</ul>\n</li>\n</ul>\n<p><strong>List</strong></p>\n<ul>\n<li><code class=\"language-text\">Array</code> 처럼 크기를 지정하지 않아도 된다.</li>\n<li>\n<p>하지만 <code class=\"language-text\">Array</code> 에서 <code class=\"language-text\">index</code> 가 중요했던 것처럼, <code class=\"language-text\">List</code> 에서는 순서가 중요하다.</p>\n<ul>\n<li>크기가 정해져있지 않아 중간에 데이터의 삽입이나 삭제가 발생해도 <code class=\"language-text\">Array</code> 보다는 덜 비효율적이다.</li>\n<li>또한 <code class=\"language-text\">index</code> 를 가지고 있기에 검색 또한 빠르다.</li>\n<li>하지만 중간에 데이터의 삽입 및 삭제 시 시간이 오래 걸리는 단점이 있다. (삽입 및 삭제 시 줄줄이 당겨지거나, 밀려날 때 수행되는 연산이 추가되고, 메모리 또한 낭비된다.)</li>\n</ul>\n</li>\n</ul>\n<p><strong>LinkedList</strong></p>\n<ul>\n<li>연결리스트에는 단일, 다중 등이 존재한다. 무슨 종류든, <strong>한 노드에 연결될 노드의 포인터 위치를 가리키는 방식</strong>이다.</li>\n</ul>\n<blockquote>\n<p>단일은 뒷 노드만 가리키고, 다중은 앞뒤 노드를 모두 가리킨다.</p>\n</blockquote>\n<ul>\n<li>데이터의 삽입 및 삭제를 하더라도, 전체를 돌지 않고 이전 값과 다음 값이 가르키고 있던 주소 값만 수정해 연결시킴으로써 빠른 수행이 가능하다.</li>\n<li>\n<p>하지만, <code class=\"language-text\">k</code> 번째 값을 찾는 문제에서는 비효율적이다.</p>\n<ul>\n<li>연결리스트에서는 <code class=\"language-text\">index</code> 가 없기 때문에, 순차 검색을 수행하므로 시간이 더 걸린다.</li>\n</ul>\n</li>\n<li>\n<p>결과적으로, 검색과 삽입 및 삭제에 대해서 <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>O</mi><mo stretchy=\"false\">(</mo><mi>N</mi><mo stretchy=\"false\">)</mo></mrow><annotation encoding=\"application/x-tex\">O(N)</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:1em;vertical-align:-0.25em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.02778em;\">O</span><span class=\"mopen\">(</span><span class=\"mord mathnormal\" style=\"margin-right:0.10903em;\">N</span><span class=\"mclose\">)</span></span></span></span>의 시간 복잡도를 가진다.</p>\n<ul>\n<li>하지만, <code class=\"language-text\">Tree</code> 구조의 근간이 되는 자료구조로, <code class=\"language-text\">Tree</code> 에서 사용되었을 때 유용하다.</li>\n</ul>\n</li>\n</ul>\n<blockquote>\n<p>상황에 맞게 자료구조를 잘 선택하는 능력이 중요하다.</p>\n</blockquote>\n<hr>\n<h2>📕 참고</h2>\n<ul>\n<li><a href=\"https://gyoogle.dev/blog/computer-science/data-structure/Array%20vs%20ArrayList%20vs%20LinkedList.html\">Tech Interview for developer</a></li>\n<li><a href=\"https://github.com/JaeYeopHan/Interview_Question_for_Beginner/tree/master/DataStructure#array-vs-linked-list\">JaeYeopHan/Interview<em>Question</em>for_Beginner</a></li>\n</ul>","frontmatter":{"title":"📂 Array vs. ArrayList vs. LinkedList","date":"May 19, 2022","update":"May 19, 2022","tags":["개발상식","Java","배열","ArrayList","연결리스트"],"series":"📂 Computer Science"},"fields":{"slug":"/[CS]Array&ArrayList&LinkedList/","readingTime":{"minutes":3.36}}},"seriesList":{"edges":[{"node":{"id":"3fe44622-13ba-589a-bbe8-01581ea7eb50","fields":{"slug":"/[CS]배열/"},"frontmatter":{"title":"📂 배열 (Array)"}}},{"node":{"id":"5b487c3d-e474-5a07-a26c-fc8c7d7cab22","fields":{"slug":"/[CS]연결리스트/"},"frontmatter":{"title":"📂 연결 리스트 (Linked List)"}}},{"node":{"id":"57149a6b-c730-5ce4-a3c5-9cea44979c8c","fields":{"slug":"/[CS]Array&ArrayList&LinkedList/"},"frontmatter":{"title":"📂 Array vs. ArrayList vs. LinkedList"}}},{"node":{"id":"28dac540-50bf-57df-afd9-9561888e8889","fields":{"slug":"/[CS]Stack&Queue/"},"frontmatter":{"title":"📂 Stack & Queue"}}},{"node":{"id":"4c2e96a9-4c71-57e3-b8e4-220b2cdf3002","fields":{"slug":"/[CS]Heap/"},"frontmatter":{"title":"📂 Heap"}}},{"node":{"id":"44f6bf8c-3235-5ff7-9d5f-f7c816218acb","fields":{"slug":"/[CS]Trie/"},"frontmatter":{"title":"📂 Trie(트라이)"}}},{"node":{"id":"81b508c5-2689-54e4-b36f-2e8bd07e2297","fields":{"slug":"/[CS]Tree/"},"frontmatter":{"title":"📂 Tree(트리)"}}},{"node":{"id":"2efb6036-05bf-594e-b9b5-03e399be6f78","fields":{"slug":"/[CS]이진탐색트리/"},"frontmatter":{"title":"📂 이진탐색트리(Binary Search Tree)"}}},{"node":{"id":"d1ac08af-f215-5176-9cd8-df1760f4ff7e","fields":{"slug":"/[CS]BTree&B+Tree/"},"frontmatter":{"title":"📂 B Tree & B+ Tree"}}}]},"previous":{"fields":{"slug":"/[Programmers]17676/"},"frontmatter":{"title":"👩‍💻 17676. 추석 트래픽"}},"next":{"fields":{"slug":"/[CS]Stack&Queue/"},"frontmatter":{"title":"📂 Stack & Queue"}}},"pageContext":{"id":"57149a6b-c730-5ce4-a3c5-9cea44979c8c","series":"📂 Computer Science","previousPostId":"3a56fa21-2504-54dd-a1f3-9990d0d6d598","nextPostId":"28dac540-50bf-57df-afd9-9561888e8889"}},"staticQueryHashes":[]}